package cn.ljy.mes.model;

import cn.ljy.common.model.BaseModel;
import cn.ljy.common.model.validate.AddWorkValidation;
import cn.ljy.common.model.validate.UpdateWorkValidation;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * 商城客户表实体类
 */
@ApiModel(value = "商城客户")
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false, of = {"id"})
public class ShopCustomer extends BaseModel {

    @ApiModelProperty(value = "客户ID", example = "28b4d848-7b7f-11f0-a22e-0250f2000002")
    @NotNull(groups = UpdateWorkValidation.class, message = "客户ID不能为空")
    private String id;

    @ApiModelProperty(value = "账户名", required = true, example = "testuser")
    @NotBlank(groups = AddWorkValidation.class, message = "账户名不能为空")
    @Length(min =3, max = 20, message = "账户名长度必须在 {min} - {max} 之间")
    private String username;

//    @ApiModelProperty(value = "登录密码", required = true, example = "123456")
//    @Length(groups = AddWorkValidation.class, min = 6, max = 20, message = "密码长度必须在 {min} - {max} 之间")
    @JSONField(serialize=false) //不将其转换为JSON,对所有fastjson插件有效。。
    @JsonIgnore //对springboot提供的json转换有效（如控制器restful接口），对fastjson插件无效。这里设计为使用fastjson转换存储redis中使用，但是在接口时不忽略密码
    private String password;

    @ApiModelProperty(value = "客户姓名", required = true, example = "张三")
    @NotBlank(groups = AddWorkValidation.class, message = "客户姓名不能为空")
    @Length(min = 2, max = 20, message = "姓名长度必须在 {min} - {max} 之间")
    private String name;

    @ApiModelProperty(value = "性别（1男 2女 0保密）", example = "1")
    @NotNull(groups = AddWorkValidation.class, message = "性别不能为空")
    @Range(min = 0, max = 2, message = "性别数值必须在 {min} - {max} 之间")
    private Integer sex;

    @ApiModelProperty(value = "手机号码", example = "13800138000")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String tel;

    @ApiModelProperty(value = "客户地址", example = "北京市朝阳区")
    @Length(max = 100, message = "地址长度不能超过 {max}")
    private String address;

    @ApiModelProperty(value = "邮政编码", example = "100000")
    @Pattern(regexp = "^[0-9]{6}$", message = "邮编必须是6位数字")
    private String zip;

    @ApiModelProperty(value = "电子邮箱", example = "test@example.com")
    @Email(message = "邮箱格式不正确")
    @Length(max = 30, message = "邮箱长度不能超过 {max}")
    private String email;

    @ApiModelProperty(value = "头像URL", example = "http://example.com/avatar.jpg")
    @Length(max = 255, message = "图片URL长度不能超过 {max}")
    private String picUrl;

    @ApiModelProperty(value = "客户简介", example = "VIP客户")
    @Length(max = 500, message = "简介长度不能超过 {max}")
    private String intro;

    @ApiModelProperty(value = "创建时间", example = "2023-01-01 12:00:00")
    private Date createTime;

    // 非数据库字段
    @ApiModelProperty(value = "订单数量", example = "5")
    private Integer orderCount;

    public ShopCustomer(String id) {
        this.id = id;
    }
}